<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title></title>
</head>

<body>
	<script src="js/mui.min.js"></script>
	<script src="js/vue.min.js"></script>
	<script src="js/url.js"></script>
	<script src="js/ajax.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">

		function GetQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		}

		var code = GetQueryString("code");
		var state = GetQueryString("state");
		var str = state.split("@");


		console.log(code);
		console.log(state);
		console.log(str);

		var proId = str[0];
		var shopId = str[1];
		var userId = str[2]; //分享者id
		var flag = str[3];
		sessionStorage.shareId = userId

		sessionStorage.shopId = shopId
		var app = new Vue({
			el: '#app',
			methods: {
				getData: function () {
					var _this = this;
					var sendStr = userId + '@' + shopId + '@' + proId + '@' + flag
					console.log(sendStr);
					console.log(code);
					ajax({
						url: newUrl + "user/toShare",
						type: 'post',
						data: {
							code: code,
							state: sendStr,
						},
						dataType: 'json',
						timeout: 10000,
						contentType: "application/json",
						success: function (data) {
							console.log();
							var data = JSON.parse(data)
							if (data.flag) {
								var results = data.data;
								if (results.flag == "error") {
									alert(results.msg);
									return;
								} else {
									sessionStorage.openId = results.openId;
									sessionStorage.user = JSON.stringify(results.user);
									sessionStorage.userId = results.user.userId == undefined ? 1 : results.user.userId
									sessionStorage.myShopId = results.user.communityId == undefined ? 0 : results.user.communityId
									sessionStorage.shop = JSON.stringify(results.shop)
									if (flag == 0) {//商品
										sessionStorage.productId = proId;
										window.location.replace("shareProduct.html")
									}
									if (flag == 9) {// 文章
										sessionStorage.topicId = proId;
										window.location.replace("shareTopic.html")
									}
									if (flag == 1) {//论坛
										sessionStorage.forumId = proId;
										window.location.replace("shareForum.html")
									}
									if (flag == 3) {//分享赚
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 4) {//邀请好友  扫描二维码
										window.location.replace("newDown.html")
									}
									if (flag == 5) {//抽奖分享
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 6) {//分享卡券
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 7) {//分享小鸡
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 8) {//趣味答题
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 10) {//抽奖有好礼
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 11) {//分享健康自测
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 12) {//好友助力
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 13) {//视频
										sessionStorage.videoId = proId;
										window.location.replace("shareVideo.html")
									}
									if (flag == 14) {//个人排行榜
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 15) {//门店排行榜
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 16) {//分享签到
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 17) {//拼团分享 group_status != 1
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 18) {//拼团分享 group_status = 1
										// sessionStorage.forumId = proId;
										// window.location.replace("shareForum.html")
									}
									if (flag == 19) {// 储值金商品
										sessionStorage.shareId = userId
										sessionStorage.productId = proId;
										window.location.replace("./rechargeProduct.html")
									}
									if (flag == 20) {//   3522 门店  储值金分享页
										window.location.replace("./3522Shop/rechargeIndex.html")
									}
									if (flag == 21) {//   3522 门店  普通商品
										sessionStorage.productId = proId;
										window.location.replace("./3522Shop/rechargeProduct.html")
									}
									if (flag == 22) {//   3522 门店  普通商品
										window.location.replace("./travel.html")
									}
									if (flag == 23) {//   3522 门店  365活动分享
										window.location.replace("./3522Shop/rechargeActive.html")
									}
									if (flag == 24) {//   分享 双12 活动
										window.location.replace("./double12Active.html")
									}
								}
							}
						},
					})
				},
			},
			created: function () {
				this.getData();
			}
		})
	</script>
</body>

</html>